// $codepro.audit.disable
package edu.gatech.oad.user;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class AccountsControllerTest {

	@Before
	public void setUp() throws Exception {
		AccountsController controller = AccountsController.sharedController();
		assertNotNull("The AccountsController was null", controller);
		
		controller.addDoctorForUsername("doctor");
		controller.addPatientForUsername("patient");
		controller.addNurseForUsername("nurse");
		controller.addReceptionistForUsername("receptionist");
		controller.addSystemAdministratorForUsername("admin");
	}
	
	@Test
	public void testGetUser() {
		AccountsController controller = AccountsController.sharedController();
		assertNotNull("The AccountsController was null", controller);
		
		//Test getting the doctor
		Doctor d = controller.getDoctorForUsername("doctor");
		assertNotNull(d);
		
		//Test getting a wrong user type
		d = controller.getDoctorForUsername("patient");
		assertNull(d);
		
		//Test getting a user
		User u = controller.getUserForUsername("patient");
		assertNotNull(u);
		
		//Test getting a patient
		Patient p = controller.getPatientForUsername("patient");
		assertNotNull(p);
		
		//Since we got a patient for the user, the patient and user should be the same
		assertSame(u, p);
		
		//Test getting a nurse
		Nurse n = controller.getNurseForUsername("nurse");
		assertNotNull(n);
		
		//Test getting a bad nurse
		n = controller.getNurseForUsername("nusre"); //typo alert (it's on purpose, though.)
		assertNull(n);
		
		//Test getting a receptionist
		Receptionist r = controller.getReceptionistForUsername("receptionist");
		assertNotNull(r);
		
		//Test getting a system administrator
		SystemAdministrator a = controller.getSystemAdministratorForUsername("admin");
		assertNotNull(a);
	}
	
	@Test
	public void testSetUser() {
		AccountsController controller = AccountsController.sharedController();
		
		//Add a patient that's already included
		Patient p = controller.addPatientForUsername("patient");
		assertNull(p);
		
		//Add a doctor that's already an administrator
		Doctor d = controller.addDoctorForUsername("admin");
		assertNull(d);
		
		//Add a good receptionist
		Receptionist r = controller.addReceptionistForUsername("erin");
		assertNotNull(r);
	}

}
